import { BaseWindow } from "../../../component/window/BaseWindow";
import { ILayer } from "../../../mvc/interfaces/ILayer";
import { Language } from "../../../../extend/language/Language";
import { WindowEvent } from "../../../component/window/WindowEvent";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { ObjCreate } from "../common/ObjCreate";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { BlessHistoryCell } from "./cellRenderer/BlessHistoryCell";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { SPublicMiniPlayer } from "../../../../Message/Public/SPublicMiniPlayer";
import { MarryBlessData } from "./defin/MarryBlessData";
import { MsgManager } from "../../manager/MsgManager";
import { Cache } from "../../cache/Cache";
import { ItemData } from "../../resource/info/ItemData";
import { ItemsUtil } from "../shortcuts/item/ItemsUtil";
import { TItem } from "../../../../Message/Db/Tables/TItem";
import { ECategory } from "../../../../Message/Public/ECategory";
import { EProp } from "../../../../Message/Public/EProp";
import { QuickBuyListWindow } from "../common/QuickBuyListWindow";
import { ShopRule } from "../../rules/ShopRule";
import { SWedding } from "../../../../Message/Public/SWedding";
import { DataProvider } from "../../../../fl/data/DataProvider";
import { AvatarInfo } from "../../resource/info/AvatarInfo";
import { AvatarType } from "../../resource/info/AvatarType";
import { ImageInfo } from "../../../../com/gengine/resource/info/ImageInfo";
import { GButton } from "../../../../com/mui/controls/GButton";
import { GTileList } from "../../../../com/mui/controls/GTileList";
import { RadioButton } from "../../../../fl/controls/RadioButton";
type int = number;
//class MarryBlessWindow
    
    export  class MarryBlessWindow extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            this.selectType = this.selectNone;
            setSize(498, 379);
            titleHeight = 26;
            title = Language.getString(43541);
            this.addEventListener(WindowEvent.SHOW, this.onWindowShow);
            return;
        }

        /* internal  */onWindowShow(arg1: WindowEvent): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.MarryGetBlessHistory, this._wedding));
            return;
        }

        protected /* override */ createChildren(): void
        {
            var loc1=null;
            var loc2=null;
            super.createChildren();
            ObjCreate.createBg(18, 39, 294, 326, this);
            ObjCreate.createBg(35, 187, 263, 170, this);
            ObjCreate.createTextField(Language.getString(43542), 37, 47, 280, 20, this);
            this._spMan = new Object /* flash.display.Sprite */();
            ObjCreate.setObjAttri(this._spMan, 52, 63, -1, -1, this);
            this._spWomen = new Object /* flash.display.Sprite */();
            ObjCreate.setObjAttri(this._spWomen, 204, 63, -1, -1, this);
            loc1 = new Object /* flash.display.Bitmap */();
            loc1.x = 0;
            loc1.y = 0;
            this._spMan.addChild(loc1);
            LoaderHelp.setBitmapdata("Friend_Bg_Head.swf", loc1);
            loc1 = new Object /* flash.display.Bitmap */();
            loc1.x = 0;
            loc1.y = 0;
            this._spWomen.addChild(loc1);
            LoaderHelp.setBitmapdata("Friend_Bg_Head.swf", loc1);
            this._headImageMan = new Object /* flash.display.Bitmap */();
            this._headImageMan.x = 17;
            this._headImageMan.y = 17;
            this._spMan.addChild(this._headImageMan);
            loc2 = GlobalStyle.textFormat2;
            loc2.align = flash.text.TextFormatAlign.CENTER;
            loc2.size = 14;
            this._tfNameMan = ObjCreate.createTextField("", 50, 165, 90, 20, this, loc2);
            this._headImageWomen = new Object /* flash.display.Bitmap */();
            this._headImageWomen.x = 17;
            this._headImageWomen.y = 17;
            this._spWomen.addChild(this._headImageWomen);
            this._tfNameWomen = ObjCreate.createTextField("", 210, 165, 90, 20, this, loc2);
            ObjCreate.createTextField(Language.getString(43543), 160, 135, 30, 20, this, loc2);
            ObjCreate.createTextField(Language.getString(43544), 78, 191, 50, 20, this, GlobalStyle.textFormat6);
            ObjCreate.createTextField(Language.getString(43545), 210, 191, 50, 20, this, GlobalStyle.textFormat6);
            this._radioButtonCoin1 = ObjCreate.createRadioButton(Language.getString(43546), 55, 220, 100, 20, this);
            this._radioButtonCoin2 = ObjCreate.createRadioButton(Language.getString(43547), 55, 248, 100, 20, this);
            this._radioButtonCoin3 = ObjCreate.createRadioButton(Language.getString(43548), 55, 276, 100, 20, this);
            this._radioButtonFlower1 = ObjCreate.createRadioButton(Language.getString(43549), 190, 220, 100, 20, this);
            this._radioButtonFlower2 = ObjCreate.createRadioButton(Language.getString(43550), 190, 248, 100, 20, this);
            this._radioButtonFlower3 = ObjCreate.createRadioButton(Language.getString(43551), 190, 276, 100, 20, this);
            this._radioButtonCoin1.groupName = "MarryBless";
            this._radioButtonCoin2.groupName = "MarryBless";
            this._radioButtonCoin3.groupName = "MarryBless";
            this._radioButtonFlower1.groupName = "MarryBless";
            this._radioButtonFlower2.groupName = "MarryBless";
            this._radioButtonFlower3.groupName = "MarryBless";
            this._btnhandsel = ObjCreate.createGButton(Language.getString(43552), 132, 325, 70, 26, this, "ButtonLarge");
            ObjCreate.createSpBannerAndBg(316, 39, 164, 326, Language.getString(43553), this);
            this._blessHistoryList = ObjCreate.createTileList(323, 72, 156, 290, this);
            this._blessHistoryList.columnWidth = 156;
            this._blessHistoryList.rowHeight = 58;
            this._blessHistoryList.setStyle("cellRenderer", BlessHistoryCell);
            this._spMan.addEventListener(flash.events.MouseEvent.CLICK, this.onSelectMan);
            this._spWomen.addEventListener(flash.events.MouseEvent.CLICK, this.onSelectWomen);
            this._btnhandsel.addEventListener(flash.events.MouseEvent.CLICK, this.onClickHandsel);
            return;
        }

        /* internal  */onSelectMan(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._spMan.filters = [FilterConst.sceneDesFilter];
            this._spWomen.filters = [];
            this.selectType = this.selectMan;
            return;
        }

        /* internal  */onSelectWomen(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._spMan.filters = [];
            this._spWomen.filters = [FilterConst.sceneDesFilter];
            this.selectType = this.selectWomen;
            return;
        }

        /* internal  */onClickHandsel(arg1: Object /* flash.events.MouseEvent */): void
        {
            var e: Object /* flash.events.MouseEvent */;
            var miniPlayer: SPublicMiniPlayer;
            var blessData: MarryBlessData;
            var flowerLevel: int;
            var propUid: string;
            var ary: Array<any>;
            var isChooseFlower: Function;
            var isRedFlower: Function;
            var i: int;

            var loc1;
            flowerLevel = 0;
            propUid = null;
            ary = null;
            i = 0;
            e = arg1;
            if (this.selectType == this.selectNone && this._wedding) 
            {
                MsgManager.showRollTipsMsg(Language.getString(43554));
                return;
            }
            miniPlayer = this.selectType != this.selectMan ? this._wedding.woman : this._wedding.man;
            if (miniPlayer.name == Cache.instance.role.entityInfo.name) 
            {
                MsgManager.showRollTipsMsg(Language.getString(43555));
                return;
            }
            blessData = new MarryBlessData(MarryBlessData.Coin, "0", miniPlayer);
            if (this._radioButtonCoin1.selected) 
            {
                blessData.type = MarryBlessData.Coin;
                blessData.data = "888";
            }
            else if (this._radioButtonCoin2.selected) 
            {
                blessData.type = MarryBlessData.Coin;
                blessData.data = "8888";
            }
            else if (this._radioButtonCoin3.selected) 
            {
                blessData.type = MarryBlessData.Coin;
                blessData.data = "88888";
            }
            else 
            {
                isChooseFlower = (arg1: ItemData): Boolean
                {
                    if (ItemsUtil.isFlower(arg1) && arg1.effect == flowerLevel) 
                    {
                        return true;
                    }
                    return false;
                }
                isRedFlower = (arg1: TItem): Boolean
                {
                    if (arg1.category == ECategory._ECategoryProp && arg1.type == EProp._EPropFlower && arg1.level == 1) 
                    {
                        return true;
                    }
                    return false;
                }
                propUid = "";
                if (this._radioButtonFlower1.selected) 
                {
                    flowerLevel = 9;
                }
                else if (this._radioButtonFlower2.selected) 
                {
                    flowerLevel = 99;
                }
                else if (this._radioButtonFlower3.selected) 
                {
                    flowerLevel = 999;
                }
                ary = Cache.instance.pack.backPackCache.getItemsByJudge(isChooseFlower);
                if (ary.length == 0) 
                {
                    QuickBuyListWindow.instace.quickUpdateDataByJudge(isRedFlower, ShopRule.ShopMallProp);
                    QuickBuyListWindow.instace.show();
                    return;
                }
                i = 0;
                while (i < ary.length) 
                {
                    propUid = (ary[i] as ItemData).uid;
                    if (ItemsUtil.isBind(ary[i] as ItemData)) 
                    {
                        break;
                    }
                    ++i;
                }
                blessData.type = MarryBlessData.Flower;
                blessData.data = propUid;
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.MarryBlessSend, blessData));
            return;
        }

        public updateData(arg1: SWedding): void
        {
            if (!arg1) 
            {
                return;
            }
            this._wedding = arg1;
            this._tfNameMan.text = arg1.man.name;
            this._tfNameWomen.text = arg1.woman.name;
            this.updateHead(arg1.man, arg1.woman);
            this._btnhandsel.visible = true;
            return;
        }

        public updateBlessHistory(arg1: Array<any>): void
        {
            this._blessHistoryList.dataProvider = new DataProvider(arg1);
            this._blessHistoryList.drawNow();
            return;
        }

        /* internal  */updateHead(arg1: SPublicMiniPlayer, arg2: SPublicMiniPlayer): void
        {
            var man: SPublicMiniPlayer;
            var woman: SPublicMiniPlayer;

            var loc1;
            man = arg1;
            woman = arg2;
            AvatarInfo.getAvatar(man.camp, man.sex, AvatarType.BIG, (arg1: ImageInfo): void
            {
                _headImageMan.bitmapData = arg1.bitmapData;
                return;
            }, man.avatarId)
            AvatarInfo.getAvatar(woman.camp, woman.sex, AvatarType.BIG, (arg1: ImageInfo): void
            {
                _headImageWomen.bitmapData = arg1.bitmapData;
                return;
            }, woman.avatarId)
            return;
        }

        /* internal */ /* const */selectNone: int=-1;

        /* internal */ /* const */selectMan: int=0;

        /* internal */ /* const */selectWomen: int=1;

        /* internal */ /* var */_wedding: SWedding;

        /* internal */ /* var */_spMan: Object /* flash.display.Sprite */;

        /* internal */ /* var */_spWomen: Object /* flash.display.Sprite */;

        /* internal */ /* var */_headImageMan: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_headImageWomen: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_tfNameMan: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfNameWomen: Object /* flash.text.TextField */;

        /* internal */ /* var */_btnhandsel: GButton;

        /* internal */ /* var */_blessHistoryList: GTileList;

        /* internal */ /* var */_radioButtonCoin1: RadioButton;

        /* internal */ /* var */_radioButtonCoin2: RadioButton;

        /* internal */ /* var */_radioButtonCoin3: RadioButton;

        /* internal */ /* var */_radioButtonFlower1: RadioButton;

        /* internal */ /* var */_radioButtonFlower2: RadioButton;

        /* internal */ /* var */_radioButtonFlower3: RadioButton;

        /* internal */ /* var */selectType: int;
    }
